package com.miracle.common.util;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.leon.lfilepickerlibrary.LFilePicker;


/**
 * com.miracle.common.util
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 * 选择文件
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/11 13:36
 * @see com.miracle.common.util
 */
public class FilePickUtil {
    public static final String FILE_PATH = "";
    public static final int REQUEST_CODE = 1000;

    public static void startFilePickView(Activity context) {
        startFilePickView(context, REQUEST_CODE);
    }

    public static void startFilePickView(Activity context, int customRequestCode) {
        new LFilePicker()
            .withActivity(context)
            .withRequestCode(customRequestCode)
             .withStartPath("/storage/emulated/0")
//             .withIsGreater(false)
//             .withFileSize(500 * 1024)
            .start();


    }

    public static void showFileChooser(Activity activity) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {
            activity.startActivityForResult(Intent.createChooser(intent, "请选择一个要上传的文件"),
                    100);
        } catch (android.content.ActivityNotFoundException ex) {
            // Potentially direct the user to the Market with a Dialog
            Toast.makeText(activity, "请安装文件管理器", Toast.LENGTH_SHORT)
                    .show();
        }
    }

}
